/**
 * 2009-11-15 上午11:23:43 
 * esignature
 * com.smc.action.document
 * DocumentHOAction
 */
package com.smc.action.document;

import java.util.List;

import com.smc.security.SecurityContextHolder;

/**
 * @author chenheng
 * @version 0.0.1
 * 表现层医院角色操作类
 */
public class DocumentHOAction extends AbstractDocumentAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6387142156387414020L;
	/**
	 * 搜索关健字
	 */
	private String searchValue ;
	/**
	 * 搜索字段
	 */
	private String searchKey ;
	/**
	 * 文档数量列表
	 */
	private List<NumDocument> numDocList ;
	///////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////// 属性值的setter and getter 方法 //////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////
	public String getSearchKey() {
		return searchKey;
	}
	public void setSearchKey(String searchKey) {
		this.searchKey = searchKey;
	}
	public String getSearchValue() {
		return searchValue;
	}
	public void setSearchValue(String searchValue) {
		this.searchValue = searchValue;
	}
	
	public List<NumDocument> getNumDocList() {
		return numDocList;
	}
	public void setNumDocList(List<NumDocument> numDocList) {
		this.numDocList = numDocList;
	}
	/**
	 * 医院用户列出医生的文档数量，包括总文档数，签名文档数和未签名文档数
	 * @return
	 */
	public String listPhysicianDocNum() {
		String uuid = SecurityContextHolder.getAuthentication(this.request.getSession()).getUUUID().toString();
		String str1 = this.request.getParameter("orderItem");
		if ( str1 == null || str1.trim().equals("")) {
			str1 = "createTime" ;
		}
		String str2 = this.request.getParameter("pageIndex");
		int pageIndex = 1 ;
		try {
			pageIndex = Integer.parseInt(str2);
		} catch (Exception ex) {
			pageIndex = 1 ;
		}
		String str3 = this.request.getParameter("pageSize");
		int pageSize = 30 ;
		try {
			pageSize = Integer.parseInt(str3);
		} catch ( Exception ex) {
			pageSize = 30 ;
		}
		int pageCount = 1 ;
		int itemCount = this.documentService.count_HO_DO_FE_documentNum(uuid);
		if ( itemCount % pageSize == 0 ) {
			pageCount = itemCount / pageSize ;
		} else {
			pageCount = itemCount / pageSize + 1 ;
		}
		numDocList = this.documentService.fetch_HO_DO_FE_documentNum(uuid,str1, pageIndex, pageSize);
		request.setAttribute("orderItem", str1);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize",pageSize);
		request.setAttribute("pageCount", pageCount);
		return SUCCESS ;
	}
	/**
	 * 医院用户列出医生的文档数量，且是按未签名文档数量排序显示
	 * @return
	 */
	public String listPhysicianRankDocNum() {
		String uuid = SecurityContextHolder.getAuthentication(this.request.getSession()).getUUUID().toString();
		String str1 = this.request.getParameter("pageIndex");
		String orderItem = this.request.getParameter("orderItem");
		if ( orderItem == null || orderItem.trim().equals("")) {
			orderItem = "COUNT(a)";
		}
		int pageIndex = 1 ;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception ex) {
			pageIndex = 1 ;
		}
		String str2 = this.request.getParameter("pageSize");
		int pageSize = 30 ;
		try {
			pageSize = Integer.parseInt(str2);
		} catch ( Exception ex) {
			pageSize = 30 ;
		}
		int pageCount = 1 ;
		int itemCount = this.documentService.count_HO_DO_FE_documentNum(uuid);
		if ( itemCount % pageSize == 0 ) {
			pageCount = itemCount / pageSize ;
		} else {
			pageCount = itemCount / pageSize + 1 ;
		}
		numDocList = this.documentService.fetch_HO_DO_FE_documentRankNum(uuid,orderItem, pageIndex, pageSize);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize",pageSize);
		request.setAttribute("pageCount", pageCount);
		return SUCCESS ;
	}
	/**
	 * 医院用户列出病人文档数量
	 * @return
	 */
	public String listPatientDocNum() {
		String uuid = SecurityContextHolder.getAuthentication(this.request.getSession()).getUUUID().toString();
		String orderItem = this.request.getParameter("orderItem");
		if ( orderItem == null || orderItem.trim().equals("")) {
			orderItem = "patient" ;
		}
		String str1 = this.request.getParameter("pageIndex");
		int pageIndex = 1 ;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception ex) {
			pageIndex = 1 ;
		}
		String str2 = this.request.getParameter("pageSize");
		int pageSize = 30 ;
		try {
			pageSize = Integer.parseInt(str2);
		} catch ( Exception ex) {
			pageSize = 30 ;
		}
		int pageCount = 1 ;
		int itemCount = this.documentService.count_HO_DO_FE_documentNum(uuid);
		if ( itemCount % pageSize == 0 ) {
			pageCount = itemCount / pageSize ;
		} else {
			pageCount = itemCount / pageSize + 1 ;
		}
		numDocList = this.documentService.fetch_HO_DO_FE_documentPatientNum(uuid, orderItem, pageIndex, pageSize);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize", pageSize);
		request.setAttribute("pageCount", pageCount);
		request.setAttribute("orderItem", orderItem);
		return SUCCESS ;
	}
	/**
	 * 医院用户列出医生已签名文档
	 * @return
	 */
	public String listSignedDocument() {
		String uuid = SecurityContextHolder.getAuthentication(this.request.getSession()).getUUUID().toString();
		String str1 = this.request.getParameter("pageIndex");
		int pageIndex = 1 ;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception ex) {
			pageIndex = 1 ;
		}
		String str2 = this.request.getParameter("pageSize");
		int pageSize = 30 ;
		try {
			pageSize = Integer.parseInt(str2);
		} catch ( Exception ex) {
			pageSize = 30 ;
		}
		int pageCount = 1; 
		int count = this.documentService.count_HO_DO_FE_documentNum(uuid, true) ;
		if ( count % pageSize == 0 ) {
			pageCount = count / pageSize ;
		} else {
			pageCount = count / pageSize + 1 ;
		}
		this.documentList = this.documentService.fetch_HO_DO_FE_document(uuid, true, pageIndex, pageSize);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize", pageSize);
		request.setAttribute("pageCount", pageCount);
		return SUCCESS ;
	}
	/**
	 * 医院用户列出医生未签名文档
	 * @return
	 */
	public String listUnSignedDocument() {
		String uuid = SecurityContextHolder.getAuthentication(this.request.getSession()).getUUUID().toString();
		String str1 = this.request.getParameter("pageIndex");
		int pageIndex = 1 ;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception ex) {
			pageIndex = 1 ;
		}
		String str2 = this.request.getParameter("pageSize");
		int pageSize = 30 ;
		try {
			pageSize = Integer.parseInt(str2);
		} catch ( Exception ex) {
			pageSize = 30 ;
		}
		int pageCount = 1; 
		int count = this.documentService.count_HO_DO_FE_documentNum(uuid, false) ;
		if ( count % pageSize == 0 ) {
			pageCount = count / pageSize ;
		} else {
			pageCount = count / pageSize + 1 ;
		}
		this.documentList = this.documentService.fetch_HO_DO_FE_document(uuid, false, pageIndex, pageSize);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize", pageSize);
		request.setAttribute("pageCount", pageCount);
		return SUCCESS ;
	}
	/**
	 * 文档搜索
	 * @return
	 */
	public String searchDocument() {
		String uuid = SecurityContextHolder.getAuthentication(this.request.getSession()).getUUUID().toString();
		String str1 = this.request.getParameter("pageIndex");
		int pageIndex = 1 ;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception ex) {
			pageIndex = 1 ;
		}
		String str2 = this.request.getParameter("pageSize");
		int pageSize = 30 ;
		try {
			pageSize = Integer.parseInt(str2);
		} catch ( Exception ex) {
			pageSize = 30 ;
		}
		String[] parameters = {searchKey,searchValue};
		int count = this.documentService.count_HO_DO_FE_document(uuid, parameters);
		int pageCount = 1 ;
		if ( count % pageSize == 0 ) {
			pageCount = count / pageSize ;
		} else {
			pageCount = count / pageSize + 1 ;
		}
		this.documentList = this.documentService.fetch_HO_DO_FE_document(uuid, parameters, pageIndex, pageSize);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize", pageSize);
		request.setAttribute("pageCount", pageCount);
		request.setAttribute("searchkey", searchKey);
		request.setAttribute("searchValue", searchValue);
		return SUCCESS ;
	}

}
